# 定义变量
REPO_URL="https://gitee.com/sweet-pear-with-warm-water/chat.git"
BRANCH="master"
OUTPUT_DIR="/usr/git/project"

# 拉取代码
echo "Cloning repository..."
git clone -b $BRANCH $REPO_URL $OUTPUT_DIR

# 进入项目目录
cd $OUTPUT_DIR

# 编译项目
echo "Building project..."
mvn clean package -Dmaven.test.skip=true

# 打印编译结果
if [ $? -eq 0 ]; then
    echo "Build successful!"
    mv $OUTPUT_DIR/target/chat-1-SNAPSHOT.jar /www/wwwroot/chat/chat-1-SNAPSHOT.jar
    rm -rf ../project
    cd /www/wwwroot/chat
    # 查找占用指定端口的进程
    pid=$(lsof -t -i:7730)
    # 如果找到了占用指定端口的进程
    if [ -n "$pid" ]; then
        echo "Process using port $port found with PID $pid. Killing it..."
        # 终止进程
        kill $pid
        echo "Process terminated."
    else
        echo "No process found using port $port."
    fi
   # nohup java -jar -Xmx1024M -Xms256M  /www/wwwroot/chat/chat-1-SNAPSHOT.jar --server.port=7730 &
else
    echo "Build failed!"
fi